<?php

	class Annualbanquet_proxy extends Model
	{
		public function __construct()
		{
			parent::__construct();
			
			$this->load->model('values/annualbanquet/Annualbanquet_registration_value');
            date_default_timezone_set($this->config->item('timezone'));
		}
						
		public function getEventName( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			bqe.description
								FROM			bq_event bqe
								WHERE			bqe.bq_event_id = ' . $eventID  . '
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->description;
			else
				return "";
		}

		public function getAdultRegistrationFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			bqe.adult_reg_fee
								FROM			bq_event bqe
								WHERE			bqe.bq_event_id = ' . $eventID  . '
								AND				bqe.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->adult_reg_fee;
			else
				return 0;
		}

		public function getChildRegistrationFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			bqe.child_reg_fee
								FROM			bq_event bqe
								WHERE			bqe.bq_event_id = ' . $eventID  . '
								AND				bqe.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->child_reg_fee;
			else
				return 0;
		}
		
		//Get total number of people registered for event
		public function getTotalNumReg( $eventID, $curyear )
		{
			
			$tmp = $this->db->query('
								SELECT			IFNULL(SUM(bqrh.numtotreg),0) AS totnumreg
								FROM			bq_reg_history bqrh
								WHERE			bqrh.bq_event_id_fk = ' . $eventID  . '
								AND				bqrh.enabled = 1
								AND				bqrh.year = ' . $this->db->escape( $curyear ) . '								
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->totnumreg;
			else
				return 0;
		}

		//Check if date for event has passed
		public function isEventValid( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			bqe.bq_event_id
								FROM			bq_event bqe
								WHERE			bqe.enabled = 1
								AND				bqe.bq_event_id = ' . $eventID  . '
								AND				NOW() < bqe.reg_close_date
							 ');
							 
			if( $tmp->num_rows() > 0)
				return TRUE;
			else
				return FALSE;
		}

		public function insertBQRegistrationPayPal( $bq_registration_value, $curyear, $pay_txn_id)
		{
			$bq_registration_value = Annualbanquet_registration_value::cast($bq_registration_value);
			$numtotreg = $bq_registration_value->getNumAdultRegistered() + $bq_registration_value->getNumChildRegistered();
			$objstrhash = md5( serialize($bq_registration_value) );			
			
			$curdate = date('Y-m-d H:i:s', time());
			$this->db->query('
								INSERT INTO			bq_reg_history
													(
														bq_event_id_fk,
														year,
														first_name,
														last_name,
														email,
														phone,
														address,
														city,
														state,
														zip,
														numtotreg,
														numadultreg,
														numchildreg,
														reg_fee_adult,
														reg_fee_child,
														donation_amount,
														payment_type,
														payment_transaction_id,
														enabled,
														date_modified,
														date_created,
														amount_paid,
														payment_status,
														is_teacher,
														teacher_discount,
														reg_fee,
														obj_string_hash
													)
								VALUES				(
														' . $this->db->escape($bq_registration_value->getEventID())  . ',
														' . $this->db->escape($curyear)  . ',
														' . $this->db->escape($bq_registration_value->getFirstName())  . ',
														' . $this->db->escape($bq_registration_value->getLastName())  . ',
														' . $this->db->escape($bq_registration_value->getEmail())  . ',
														' . $this->db->escape($bq_registration_value->getPhone())  . ',
														' . $this->db->escape($bq_registration_value->getAddress())  . ',
														' . $this->db->escape($bq_registration_value->getCity())  . ',
														' . $this->db->escape($bq_registration_value->getState())  . ',
														' . $this->db->escape($bq_registration_value->getZip())  . ',
														' . $this->db->escape($numtotreg)  . ',
														' . $this->db->escape($bq_registration_value->getNumAdultRegistered())  . ',
														' . $this->db->escape($bq_registration_value->getNumChildRegistered())  . ',
														' . $this->db->escape($bq_registration_value->getRegistrationFeeAdult())  . ',
														' . $this->db->escape($bq_registration_value->getRegistrationFeeChild())  . ',
														' . $this->db->escape($bq_registration_value->getDonation())  . ',
														' . $this->db->escape("paypal")  . ',
														' . $this->db->escape($pay_txn_id)  . ',
														1,
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														' . $this->db->escape($bq_registration_value->getTotalRegistrationFee())  . ',
														1,
														' . $this->db->escape($bq_registration_value->getIsTeacher())  . ',
														' . $this->db->escape($bq_registration_value->getTeacherDiscount())  . ',
														' . $this->db->escape($bq_registration_value->getRegistrationFee())  . ',
														' . $this->db->escape($objstrhash)  . '														
													)
							 ');
			
			$tmp = $this->db->query('
													SELECT 		bq_reg_history_id 
													FROM 		bq_reg_history
													WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
												  ');

			if( $tmp->num_rows() == 1 )
			{
				$BQRegHistoryId = $tmp->row()->bq_reg_history_id;
			}
			else
				$BQRegHistoryId = 0;
			
			return $BQRegHistoryId;
		}

		public function insertBQRegistrationCheck( $bq_registration_value, $curyear)
		{
			$bq_registration_value = Annualbanquet_registration_value::cast($bq_registration_value);
			$numtotreg = $bq_registration_value->getNumAdultRegistered() + $bq_registration_value->getNumChildRegistered();
			$objstrhash = md5( serialize($bq_registration_value) );			
			
			$curdate = date('Y-m-d H:i:s', time());
			$this->db->query('
								INSERT INTO			bq_reg_history
													(
														bq_event_id_fk,
														year,
														first_name,
														last_name,
														email,
														phone,
														address,
														city,
														state,
														zip,
														numtotreg,
														numadultreg,
														numchildreg,
														reg_fee_adult,
														reg_fee_child,
														donation_amount,
														payment_type,
														enabled,
														date_modified,
														date_created,
														amount_paid,
														payment_status,
                                                        is_teacher,
                                                        teacher_discount,
                                                        reg_fee,
														obj_string_hash
													)
								VALUES				(
														' . $this->db->escape($bq_registration_value->getEventID())  . ',
														' . $this->db->escape($curyear)  . ',
														' . $this->db->escape($bq_registration_value->getFirstName())  . ',
														' . $this->db->escape($bq_registration_value->getLastName())  . ',
														' . $this->db->escape($bq_registration_value->getEmail())  . ',
														' . $this->db->escape($bq_registration_value->getPhone())  . ',
														' . $this->db->escape($bq_registration_value->getAddress())  . ',
														' . $this->db->escape($bq_registration_value->getCity())  . ',
														' . $this->db->escape($bq_registration_value->getState())  . ',
														' . $this->db->escape($bq_registration_value->getZip())  . ',
														' . $this->db->escape($numtotreg)  . ',
														' . $this->db->escape($bq_registration_value->getNumAdultRegistered())  . ',
														' . $this->db->escape($bq_registration_value->getNumChildRegistered())  . ',
														' . $this->db->escape($bq_registration_value->getRegistrationFeeAdult())  . ',
														' . $this->db->escape($bq_registration_value->getRegistrationFeeChild())  . ',
														' . $this->db->escape($bq_registration_value->getDonation())  . ',
														' . $this->db->escape("check")  . ',
														1,
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														' . $this->db->escape($bq_registration_value->getTotalRegistrationFee())  . ',
														2,
                                                        ' . $this->db->escape($bq_registration_value->getIsTeacher())  . ',
                                                        ' . $this->db->escape($bq_registration_value->getTeacherDiscount())  . ',
                                                        ' . $this->db->escape($bq_registration_value->getRegistrationFee())  . ',
														' . $this->db->escape($objstrhash)  . '														
													)
							 ');
			
			$tmp = $this->db->query('
													SELECT 		bq_reg_history_id 
													FROM 		bq_reg_history
													WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
												  ');

			if( $tmp->num_rows() == 1 )
			{
				$BQRegHistoryId = $tmp->row()->bq_reg_history_id;
			}
			else
				$BQRegHistoryId = 0;
			
			return $BQRegHistoryId;			
		}

		public function updateBanquetRegistration( $bq_registration_value, $status )
		{
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/annualbanquet/Annualbanquet_proxy');
			$this->load->model('values/annualbanquet/Annualbanquet_registration_value');
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$bq_registration_value = Annualbanquet_registration_value::cast($bq_registration_value);
			
			//Set dependent field values
			$numtotreg = $bq_registration_value->getNumAdultRegistered() + $bq_registration_value->getNumChildRegistered();

			$tmp = $this->db->query('
								UPDATE	bq_reg_history
								SET		first_name = ' . $this->db->escape($bq_registration_value->getFirstName()) . ',
										last_name = ' . $this->db->escape($bq_registration_value->getLastName()) . ',
										email = ' . $this->db->escape($bq_registration_value->getEmail()) . ',
										phone = ' . $this->db->escape($bq_registration_value->getPhone()) . ',
										address = ' . $this->db->escape($bq_registration_value->getAddress()) . ',
										city = ' . $this->db->escape($bq_registration_value->getCity()) . ',
										state = ' . $this->db->escape($bq_registration_value->getState()) . ',
										zip = ' . $this->db->escape($bq_registration_value->getZip()) . ',
										numtotreg = ' . $this->db->escape($numtotreg) . ',
										numadultreg = ' . $this->db->escape($bq_registration_value->getNumAdultRegistered()) . ',
										numchildreg = ' . $this->db->escape($bq_registration_value->getNumChildRegistered()) . ',
										payment_type = ' . $this->db->escape($bq_registration_value->getPaymentType()) . ',
										payment_transaction_id = ' . $this->db->escape($bq_registration_value->getPaymentTransactionID()) . ',
										payment_status = ' . $this->db->escape($bq_registration_value->getPaymentStatus()) . ',
										check_num = ' . $this->db->escape($bq_registration_value->getCheckNum()) . ',
										donation_amount = ' . $this->db->escape($bq_registration_value->getDonation()) . ',
										amount_paid = ' . $this->db->escape($bq_registration_value->getTotalRegistrationFee()) . ',
										comments = ' . $this->db->escape($bq_registration_value->getComments()) . ',
										enabled = ' . $this->db->escape( $status ) . ',
										date_modified = Now()
								WHERE	bq_reg_history_id = ' . $this->db->escape($bq_registration_value->getBQRegHistoryID()) . '
							 ');
							 
			return $bq_registration_value->getBQRegHistoryID();
		}

		//Check if person already registered for event 
		public function isEventRegistered( $eventID, $firstname, $lastname, $email_contact, $curyear )
		{
			
			$tmp = $this->db->query('
								SELECT			bqrh.bq_reg_history_id
								FROM			bq_reg_history bqrh
								WHERE			bqrh.first_name = ' . $this->db->escape($firstname) . '
								AND				bqrh.last_name = ' . $this->db->escape($lastname) . '
								AND				bqrh.email = ' . $this->db->escape($email_contact) . '
								AND				bqrh.bq_event_id_fk = ' . $this->db->escape($eventID) . '
								AND				bqrh.enabled = 1
								AND             bqrh.year = ' . $this->db->escape($curyear) . '
							 ');
							 
			if( $tmp->num_rows() > 0)
				return TRUE;
			else
				return FALSE;
		}

		public function getEventUnpaidCheckInfo( $curyear )
		{
			
			$unpaidchecklist = $this->db->query('
												SELECT    	bqrh.bq_reg_history_id,
															bqrh.first_name,
												          	bqrh.last_name,
															bqrh.email,
															bqrh.numtotreg,
															bqrh.amount_paid,
															bqe.description,
															bqrh.phone,
															bqrh.address,
															bqrh.city,
															bqrh.state,
															bqrh.zip
												FROM      	bq_reg_history bqrh
															INNER JOIN bq_event bqe ON bqe.bq_event_id=bqrh.bq_event_id_fk
												WHERE       bqrh.payment_status <> 1
												AND			bqrh.payment_type = ' . $this->db->escape( 'check' ) . '
												AND			bqrh.year = ' . $this->db->escape( $curyear ) . '
												AND			bqrh.enabled = 1
											  ');

			
			$regInfo = array();
			if( $unpaidchecklist->num_rows() > 0)
			{
				foreach ($unpaidchecklist->result() as $regIdRow)
				{
					$checkInfo = array();		
					array_push($checkInfo, $regIdRow->bq_reg_history_id);					
					array_push($checkInfo, $regIdRow->first_name);					
					array_push($checkInfo, $regIdRow->last_name);					
					array_push($checkInfo, $regIdRow->email);					
					array_push($checkInfo, $regIdRow->numtotreg);					
					array_push($checkInfo, $regIdRow->amount_paid);					
					array_push($checkInfo, $regIdRow->description);					
					array_push($checkInfo, $regIdRow->phone);					
					array_push($checkInfo, $regIdRow->address);					
					array_push($checkInfo, $regIdRow->city);					
					array_push($checkInfo, $regIdRow->state);					
					array_push($checkInfo, $regIdRow->zip);					
					
					array_push($regInfo, $checkInfo);					
				}
			}
				
			return $regInfo;
		}

		public function getEventUnpaidCheckRegId( $curyear )
		{
			
			$unpaidchecklist = $this->db->query('
												SELECT    	bqrh.bq_reg_history_id
												FROM      	bq_reg_history bqrh
												WHERE       bqrh.payment_status <> 1
												AND			bqrh.payment_type = ' . $this->db->escape( 'check' ) . '
												AND			bqrh.year = ' . $this->db->escape( $curyear ) . '
												AND			bqrh.enabled = 1
											  ');
			
			$regId = array();
			if( $unpaidchecklist->num_rows() > 0)
			{
				foreach ($unpaidchecklist->result() as $regIdRow)
				{
					array_push($regId, $regIdRow->bq_reg_history_id);					
				}
			}
				
			return $regId;
		}

		public function completeBQRegistrationCheck( $bqRegHistoryId, $checknum )
		{
			
			$this->db->query('
								UPDATE			bq_reg_history
								SET				payment_status = 1,
												check_num = ' . $this->db->escape($checknum) . ',
												date_modified = Now()
								WHERE			bq_reg_history_id = ' . $bqRegHistoryId  . '
								AND				payment_type = ' . $this->db->escape('check') . '
							 ');
							 
			return $bqRegHistoryId;
		}

		//Get event value object
		public function getEventInfoYear( $bqRegHistoryId, $curyear )
		{
			$this->load->model('values/annualbanquet/Annualbanquet_registration_value');			
			
			$eventlist = $this->db->query('
												SELECT    	bqrh.bq_reg_history_id,
															bqrh.first_name,
												          	bqrh.last_name,
															bqrh.email,
															bqrh.phone,
															bqrh.address,
															bqrh.city,
															bqrh.state,
															bqrh.zip,
															bqrh.numadultreg,
															bqrh.numchildreg,
															bqrh.payment_type,
															bqrh.check_num,
															bqrh.payment_transaction_id,
															bqrh.payment_status,
															bqrh.reg_fee_adult,
															bqrh.reg_fee_child,
															bqrh.donation_amount,
															bqrh.amount_paid,
															bqrh.bq_event_id_fk,
															bqrh.comments
												FROM      	bq_reg_history bqrh
												WHERE       bqrh.bq_reg_history_id = ' . $this->db->escape( $bqRegHistoryId ) . '
												AND			bqrh.year = ' . $this->db->escape( $curyear ) . '
												AND			bqrh.enabled = 1
											  ');

			
			$bq_registration_value = new Annualbanquet_registration_value();
			if( $eventlist->num_rows() > 0)
			{
				foreach ($eventlist->result() as $regIdRow)
				{		
					$bq_registration_value->setBQRegHistoryID($regIdRow->bq_reg_history_id);
					$bq_registration_value->setEventID($regIdRow->bq_event_id_fk);
					$bq_registration_value->setCurrentYear($curyear);
					$bq_registration_value->setFirstName($regIdRow->first_name);
					$bq_registration_value->setLastName($regIdRow->last_name);
					$bq_registration_value->setEmail($regIdRow->email);
					$bq_registration_value->setPhone($regIdRow->phone);
					$bq_registration_value->setAddress($regIdRow->address);
					$bq_registration_value->setCity($regIdRow->city);
					$bq_registration_value->setState($regIdRow->state);
					$bq_registration_value->setZip($regIdRow->zip);
					$bq_registration_value->setNumAdultRegistered($regIdRow->numadultreg);
					$bq_registration_value->setNumChildRegistered($regIdRow->numchildreg);
					$bq_registration_value->setRegistrationFeeAdult( $regIdRow->reg_fee_adult );
					$bq_registration_value->setRegistrationFeeChild( $regIdRow->reg_fee_child );
					$bq_registration_value->setDonation( $regIdRow->donation_amount );
					$bq_registration_value->setPaymentType( $regIdRow->payment_type );
					$bq_registration_value->setCheckNum( $regIdRow->check_num );
					$bq_registration_value->setPaymentTransactionID( $regIdRow->payment_transaction_id );
					$bq_registration_value->setPaymentStatus( $regIdRow->payment_status );
					$bq_registration_value->setComments( $regIdRow->comments );
				}
			}
				
			return $bq_registration_value;
		}

		//Get all banquet registrations
		public function getAllBanquetRegistrations( $curyear )
		{
			$this->load->model('proxies/annualbanquet/Annualbanquet_proxy');
			$this->load->model('values/annualbanquet/Annualbanquet_registration_value');

			$bqreglist = $this->db->query('
						SELECT 	bqrh.bq_reg_history_id,
								bqrh.first_name,
								bqrh.last_name,
								bqrh.email,
								bqrh.phone,
								bqrh.address,
								bqrh.city,
								bqrh.state,
								bqrh.zip,
								bqrh.numadultreg,
								bqrh.numchildreg,
								bqrh.reg_fee_adult,
								bqrh.reg_fee_child,
								bqrh.payment_type,
								bqrh.payment_transaction_id,
								bqrh.payment_status,
								bqrh.check_num,
								bqrh.donation_amount,
								bqrh.is_teacher,
								bqrh.comments
						FROM bq_reg_history bqrh
						WHERE bqrh.enabled = 1
						AND bqrh.year =  ' . $this->db->escape( $curyear ) . '
						ORDER BY bqrh.bq_reg_history_id DESC;
					');
								
			$regInfo = array();
			if( $bqreglist->num_rows() > 0)
			{
				foreach ($bqreglist->result() as $regRow)
				{
					$bq_registration_value = new Annualbanquet_registration_value();
					
					$bq_registration_value->setCurrentYear( $curyear );
					$bq_registration_value->setBQRegHistoryID( $regRow->bq_reg_history_id );	
					$bq_registration_value->setFirstName( $regRow->first_name );
					$bq_registration_value->setLastName( $regRow->last_name );
					$bq_registration_value->setEmail( $regRow->email );
					$bq_registration_value->setPhone( $regRow->phone );
					$bq_registration_value->setAddress( $regRow->address );
					$bq_registration_value->setCity( $regRow->city );
					$bq_registration_value->setState( $regRow->state );
					$bq_registration_value->setZip( $regRow->zip );
					$bq_registration_value->setNumAdultRegistered( $regRow->numadultreg );
					$bq_registration_value->setNumChildRegistered( $regRow->numchildreg );
					$bq_registration_value->setRegistrationFeeAdult( $regRow->reg_fee_adult );
					$bq_registration_value->setRegistrationFeeChild( $regRow->reg_fee_child );					
					$bq_registration_value->setPaymentType( $regRow->payment_type );
					$bq_registration_value->setPaymentTransactionID( $regRow->payment_transaction_id );
					$bq_registration_value->setPaymentStatus( $regRow->payment_status );
					$bq_registration_value->setCheckNum( $regRow->check_num );					
					$bq_registration_value->setDonation( $regRow->donation_amount );
					$bq_registration_value->setComments( $regRow->comments );
                    $bq_registration_value->setIsTeacher( $regRow->is_teacher );
										
					array_push($regInfo, $bq_registration_value);
				}
			}
				
			return $regInfo;
		}

		//Confirms registration after payment is confirmed through Paypal ipn
		public function sendEventRegistrationConfirmEmailPaypal( $bq_registration_value, $desc, $curyear, $paypal_txn_id )
		{
			$this->load->library('encrypt');

			$bq_registration_value = Annualbanquet_registration_value::cast($bq_registration_value);
			$desc = $this->getEventName( $bq_registration_value->getEventID() );
			
			$message = '';
			$message .= '<p><b>You have Been Registered for ' . $curyear . ' ' . $desc.'</b></p>';
			$message .= '<p>Hari OM ' . $bq_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>Your registration for ' . $curyear . ' ' . $desc . ' has been confirmed:</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Name:</td><td>' . $bq_registration_value->getFirstName() . ' ' . $bq_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $bq_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $bq_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address:</td><td>' . $bq_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $bq_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State:</td><td>' . $bq_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Zip:</td><td>' . $bq_registration_value->getZip() . '</td></tr>';
			$message .= '<tr><td width="250">#Adults (2yrs & older):</td><td>' . $bq_registration_value->getNumAdultRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">#Children (less than 2yrs):</td><td>' . $bq_registration_value->getNumChildRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $bq_registration_value->getTotalNumRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $bq_registration_value->getRegistrationFee() . '</td></tr>';
			if ($bq_registration_value->getIsTeacher() == 1)
			   $message .= '<tr><td width="250">Teacher Discount:</td><td>($' . $bq_registration_value->getTeacherDiscount() . ')</td></tr>';
            //$message .= '<tr><td width="250">Child Registration Fee:</td><td>$' . ($bq_registration_value->getNumChildRegistered()*$bq_registration_value->getRegistrationFeeChild()) . '</td></tr>';
			$message .= '<tr><td width="250">Donation:</td><td>$' . $bq_registration_value->getDonation() . '</td></tr>';
			$message .= '<tr><td width="250">Total Amount:</td><td>$' . $bq_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Paypal Transaction ID:</td><td>' . $paypal_txn_id . '</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $bq_registration_value->getEmail() );
			$this->email->cc('');
			$this->email->bcc('cmbproject@gmail.com');
			
			$this->email->subject('Registration confirmation for ' . $curyear .' '. $desc);
			$this->email->message($message);
			
			$this->email->send();
		}

		//Email with information about sending check after person has chosen to pay by check
		public function sendEventRegistrationByCheckEmail( $bq_registration_value, $desc, $curyear )
		{
			$bq_registration_value = Annualbanquet_registration_value::cast($bq_registration_value);
			
			$message = '';
			$message .= '<p>Hari OM ' . $bq_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>We received your registration request with payment by <u>check</u> for ' . $curyear . ' '. $desc .':</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Name:</td><td>' . $bq_registration_value->getFirstName() . ' ' . $bq_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $bq_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $bq_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address:</td><td>' . $bq_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $bq_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State:</td><td>' . $bq_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Zip:</td><td>' . $bq_registration_value->getZip() . '</td></tr>';
            $message .= '<tr><td width="250">#Adults (2yrs & older):</td><td>' . $bq_registration_value->getNumAdultRegistered() . '</td></tr>';
            $message .= '<tr><td width="250">#Children (less than 2yrs):</td><td>' . $bq_registration_value->getNumChildRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $bq_registration_value->getTotalNumRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $bq_registration_value->getRegistrationFee() . '</td></tr>';
            if ($bq_registration_value->getIsTeacher() == 1)
               $message .= '<tr><td width="250">Teacher Discount:</td><td>($' . $bq_registration_value->getTeacherDiscount() . ')</td></tr>';
			$message .= '<tr><td width="250">Donation:</td><td>$' . $bq_registration_value->getDonation() . '</td></tr>';
			$message .= '<tr><td width="250">Total Amount Due:</td><td>$' . $bq_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Please write a check for <b>$' . $bq_registration_value->getTotalRegistrationFee() . '</b>, payable to <u>Chinmaya Mission Boston</u>. Mail the check to:</p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250"></td><td>ATTN: '.$curyear.' '.$desc.' Registration</td></tr>';
			$message .= '<tr><td width="250"></td><td>Chinmaya Mission Boston</td></tr>';
			$message .= '<tr><td width="250"></td><td>1 Union Street</td></tr>';
			$message .= '<tr><td width="250"></td><td>Andover, MA  01810</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>You will receive a confirmation email once we receive your check. We would like to thank you for your support.</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $bq_registration_value->getEmail() );
			$this->email->cc('cmbproject@gmail.com');
			
			$this->email->subject('Payment by check for ' . $curyear . ' '. $desc);
			$this->email->message($message);
			
			$this->email->send();
		}	

		//Confirms registration after payment via check is released
		public function sendEventRegistrationCheckConfirmEmail( $bq_registration_value, $curyear)
		{
			$this->load->library('encrypt');

			$bq_registration_value = Annualbanquet_registration_value::cast($bq_registration_value);
			
			$desc = $this->getEventName( $bq_registration_value->getEventID() );
			
			$message = '';
			$message .= '<p><b>You have Been Registered for ' . $curyear . ' ' . $desc.'</b></p>';
			$message .= '<p>Hari OM ' . $bq_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>Your registration for ' . $curyear . ' ' . $desc . ' has been confirmed:</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Name:</td><td>' . $bq_registration_value->getFirstName() . ' ' . $bq_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $bq_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $bq_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address:</td><td>' . $bq_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $bq_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State:</td><td>' . $bq_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Zip:</td><td>' . $bq_registration_value->getZip() . '</td></tr>';
            $message .= '<tr><td width="250">#Adults (2yrs & older):</td><td>' . $bq_registration_value->getNumAdultRegistered() . '</td></tr>';
            $message .= '<tr><td width="250">#Children (less than 2yrs):</td><td>' . $bq_registration_value->getNumChildRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $bq_registration_value->getTotalNumRegistered() . '</td></tr>';
			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $bq_registration_value->getRegistrationFee() . '</td></tr>';
            if ($bq_registration_value->getIsTeacher() == 1)
               $message .= '<tr><td width="250">Teacher Discount:</td><td>($' . $bq_registration_value->getTeacherDiscount() . ')</td></tr>';
			$message .= '<tr><td width="250">Donation:</td><td>$' . $bq_registration_value->getDonation() . '</td></tr>';
			$message .= '<tr><td width="250">Total Fee:</td><td>$' . $bq_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Check#:</td><td>' . $bq_registration_value->getCheckNum() . '</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $bq_registration_value->getEmail() );
			$this->email->cc('');
			$this->email->bcc('cmbproject@gmail.com');
			
			$this->email->subject('Registration confirmation for ' . $curyear .' '. $desc);
			$this->email->message($message);
			
			$this->email->send();
		}
	}
?>